<?php
namespace src\lib;

use src\Curl;

/**
 * 阿里巴巴图床
 * Class Alibaba
 * @package src\lib
 * @url https://www.alibaba.com/
 */

class Alibaba
{

    public function upload($path)
    {
        $data = [
            'file' => Curl::getCurlFile($path),
            'scene' => 'aeMessageCenterV2ImageRule',
            'name' => 'image.jpg'
        ];

        $result = Curl::post('https://kfupload.alibaba.com/mupload', $data, [
            CURLOPT_USERAGENT => 'iAliexpress/6.22.1 (iPhone; iOS 12.1.2; Scale/2.00)',
        ]);

        $json = json_decode($result, true);
        if(isset($json['code']) && $json['code'] == 0 && isset($json['url'])){
            return $json['url'];
        }

        return false;
    }
}